﻿using System;
using MessagePack.Formatters;
using MessagePack.Unity;

namespace MessagePack.Resolvers
{
	// Token: 0x02000128 RID: 296
	public class StandardResolver : IFormatterResolver
	{
		// Token: 0x06000460 RID: 1120 RVA: 0x00013863 File Offset: 0x00011C63
		private StandardResolver()
		{
		}

		// Token: 0x06000461 RID: 1121 RVA: 0x0001386B File Offset: 0x00011C6B
		public IMessagePackFormatter<T> GetFormatter<T>()
		{
			return StandardResolver.FormatterCache<T>.formatter;
		}

		// Token: 0x040001ED RID: 493
		public static readonly IFormatterResolver Instance = new StandardResolver();

		// Token: 0x040001EE RID: 494
		private static readonly IFormatterResolver[] resolvers = new IFormatterResolver[]
		{
			BuiltinResolver.Instance,
			UnityResolver.Instance,
			DynamicEnumResolver.Instance,
			DynamicGenericResolver.Instance,
			DynamicUnionResolver.Instance,
			DynamicObjectResolver.Instance,
			PrimitiveObjectResolver.Instance
		};

		// Token: 0x02000129 RID: 297
		private static class FormatterCache<T>
		{
			// Token: 0x06000463 RID: 1123 RVA: 0x000138D0 File Offset: 0x00011CD0
			static FormatterCache()
			{
				foreach (IFormatterResolver formatterResolver in StandardResolver.resolvers)
				{
					IMessagePackFormatter<T> messagePackFormatter = formatterResolver.GetFormatter<T>();
					if (messagePackFormatter != null)
					{
						StandardResolver.FormatterCache<T>.formatter = messagePackFormatter;
						return;
					}
				}
			}

			// Token: 0x040001EF RID: 495
			public static readonly IMessagePackFormatter<T> formatter;
		}
	}
}
